import { request } from '../request';

/** get role list */
export function fetchGetRoleList(params?: Api.SystemManage.RoleSearchParams) {
  return request<Api.SystemManage.RoleList>({
    url: '/systemManage/getRoleList',
    method: 'get',
    params
  });
}

/** create role */
export function fetchCreateRole(data: Api.SystemManage.CreateRoleParams) {
  return request<Api.SystemManage.Role>({
    url: '/systemManage/createRole',
    method: 'post',
    data
  });
}
/** update role */
export function fetchUpdateRole(data: Api.SystemManage.UpdateRoleParams) {
  const { id, ...rest } = data;
  return request<Api.SystemManage.Role>({
    url: `/systemManage/updateRole/${id}`,
    method: 'patch',
    data: rest
  });
}
/** CheckedMenuByRole */
export function fetchGetCheckedMenuByRole(id: number) {
  return request<Api.SystemManage.munuIds>({
    url: `/systemManage/getCheckedMenuByRole/${id}`,
    method: 'get'
  });
}

/** delete user */
export function fetchDeleteRole(ids: Api.SystemManage.DeleteIds) {
  return request<Api.Common.SuccessResponseData>({
    url: `/systemManage/deleteRole/${ids.join(',')}`,
    method: 'delete'
  });
}

/**
 * get all roles
 *
 * these roles are all enabled
 */
export function fetchGetAllRoles() {
  return request<Api.SystemManage.AllRole[]>({
    url: '/systemManage/getAllRoles',
    method: 'get'
  });
}

/** get user list */
export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
  return request<Api.SystemManage.UserList>({
    url: '/systemManage/getUserList',
    method: 'get',
    params
  });
}

/** create user */
export function fetchCreateUser(data: Api.SystemManage.CreateUserParams) {
  return request<Api.SystemManage.User>({
    url: '/systemManage/createUser',
    method: 'post',
    data
  });
}

/** update user */
export function fetchUpdateUser(data: Api.SystemManage.UpdateUserParams) {
  const { id, ...rest } = data;
  return request<Api.Common.SuccessResponseData>({
    url: `/systemManage/updateUser/${id}`,
    method: 'patch',
    data: rest
  });
}

/** delete user */
export function fetchDeleteUser(ids: Api.SystemManage.DeleteIds) {
  return request<Api.Common.SuccessResponseData>({
    url: `/systemManage/deleteUser/${ids.join(',')}`,
    method: 'delete'
  });
}

/** get menu list */
export function fetchGetMenuList() {
  return request<Api.SystemManage.MenuList>({
    url: '/systemManage/getMenuList/v2',
    method: 'get'
  });
}

/** get all pages */
export function fetchGetAllPages() {
  return request<string[]>({
    url: '/systemManage/getAllPages',
    method: 'get'
  });
}

/** get menu tree */
export function fetchGetMenuTree() {
  return request<Api.SystemManage.MenuTree[]>({
    url: '/systemManage/getMenuTree',
    method: 'get'
  });
}

/** create menu */
export function fetchCreateMenu(data: Api.SystemManage.CreateMenuParams) {
  return request<Api.SystemManage.Menu>({
    url: '/systemManage/createMenu',
    method: 'post',
    data
  });
}

/** uodate menu */
export function fetchUpdateMenu(data: Api.SystemManage.UpdateMenuParams) {
  const { id, ...rest } = data;
  return request<Api.SystemManage.Menu>({
    url: `/systemManage/updateMenu/${id}`,
    method: 'patch',
    data: rest
  });
}

/** delete menu */
export function fetchDeleteMenu(ids: Api.SystemManage.DeleteIds) {
  return request<Api.Common.SuccessResponseData>({
    url: `/systemManage/deleteMenu/${ids.join(',')}`,
    method: 'delete'
  });
}

/** get all */
export function fetchGetAllPermissions() {
  return request<Api.SystemManage.Permission[]>({
    url: '/systemManage/allPermissions',
    method: 'get'
  });
}

/** CheckedMenuByRole */
export function fetchGetCheckedButtonByRole(id: number) {
  return request<Api.SystemManage.buttonIds>({
    url: `/systemManage/getCheckedButtonByRole/${id}`,
    method: 'get'
  });
}
